package com.classify.system.service.impl;

import com.classify.system.domain.SgAttributes;
import com.classify.system.mapper.SgAttributesMapper;
import com.classify.system.service.ISgAttributesService;
import com.shopgoods.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @ClassName SgAttributesServiceImpl
 * @Description 描述
 * @Author GYW
 * @Date 2024-11-15 10:33
 */
@Service
public class SgAttributesServiceImpl  implements ISgAttributesService {

    @Autowired
    private SgAttributesMapper sgAttributesMapper;


    /**
     * 查询所有
     *
     * @return
     */
    @Override
    public List<SgAttributes> findlist() {

        List<SgAttributes> findlist = sgAttributesMapper.findlist(0);

        findChildList(findlist);

        return findlist;
    }

    private void findChildList(List<SgAttributes> findlist) {

        for (SgAttributes sgAttributes : findlist) {

            List<SgAttributes> list = sgAttributesMapper.findlist(sgAttributes.getAid());

            if (!StringUtils.isEmpty(list)){
                findChildList(list);
            }
            sgAttributes.setChildren(list);
        }
    }
}
